package com.hqhsc.module.front.activity.controller;

import com.hqhsc.module.front.activity.service.SignupService;
import com.hqhsc.module.init.service.InitService;
import com.hqhsc.module.manage.activity.domain.Activity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Properties;

@Controller
@RequestMapping("/activity/signup")
public class SignupController {
	final Logger logger = LoggerFactory.getLogger(SignupController.class);

	@Autowired
	private SignupService signupService;
    @Autowired
    private SignupService activityService;
    @Autowired
    private InitService initService;
	@Autowired
	private Properties appProps;

    /**
     * 用户展示页面-报名页
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/normal" , method = RequestMethod.GET)
    public String signup(Model model , HttpServletRequest request , HttpServletResponse response) {

        String activity_id_str = request.getParameter("aid");
        String channel_id_str = request.getParameter("cid");

        Activity activity = this.activityService.getActivityById(request , Long.valueOf(activity_id_str) , Long.valueOf(channel_id_str));

        model.addAttribute("aid" , activity_id_str);
        model.addAttribute("cid" , channel_id_str);
        model.addAttribute("activity" , activity);
        return "/module/front/activity/signup/normal";
    }

    /**
     * 用户报名
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/dosignup" , method = RequestMethod.POST)
    @ResponseBody
    public int doSignUp(Model model , HttpServletRequest request , HttpServletResponse response) {

        String activity_id_str = request.getParameter("aid");
        String channel_id_str = request.getParameter("cid");

        String user_name = request.getParameter("userName");
        String sex = request.getParameter("userSex");
        String dn = request.getParameter("userTel");
        String id_card = request.getParameter("userIdCard");
        String address = request.getParameter("userAddress");
        String budget = request.getParameter("userPay");
        String wedding_date = request.getParameter("userTime");
        String marry_require = request.getParameter("userDemands");
        String other_require = request.getParameter("userDemandsOher");


        return this.signupService.signupActivityUser(Long.valueOf(activity_id_str) , Long.valueOf(channel_id_str) ,
                user_name , sex , dn , id_card , address , budget , wedding_date , marry_require , other_require);
    }
}